-
Notifications
You must be signed in to change notification settings - Fork 38
Allow decimal notation for multiple types by scoping builtin map… #1326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
I think we can start the review @fblanqui. I removed the tag WIP. |
|
Hum, the CI is failing at the export test, but I do not know how we should modify the |
fblanqui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Alessio. Thank you for your PR. I started to review it. I think that we do not need to have so many changes, and to change the type of sig_state. You should simply modify the function Builtin.get in a way similar to Sig_state.find_sym:
let get : sig_state -> popt -> Path.t -> string -> sym = fun ss pos mp name ->
try
match mp with
| [] -> StrMap.find name ss.builtins
| [m] when StrMap.mem m ss.alias_path -> (* Aliased module path. *)
(* The signature must be loaded (alias is mapped). *)
let sign =
try Path.Map.find (StrMap.find m ss.alias_path) !loaded
with _ -> assert false (* Should not happen. *)
in
(* Look for the symbol. *)
StrMap.find !(sign.sign_builtins) name
| _ ->
(* Check that the signature was required (or is the current one). *)
if mp <> ss.signature.sign_path then
if not (Path.Map.mem mp !(ss.signature.sign_deps)) then
fatal pos "No module [%a] required." Path.pp mp;
(* The signature must have been loaded. *)
let sign =
try Path.Map.find mp !loaded
with Not_found -> assert false (* Should not happen. *)
in
(* Look for the builtin. *)
StrMap.find !(sign.sign_builtins) name
with Not_found ->
if mp=[] then fatal pos "Builtin symbol \"%s\" undefined." name
else fatal pos "Builtin symbol \"%a.%s\" undefined." Path.pp mp name
src/parsing/pretty.ml
Outdated
| out ppf "@[@[<hv2>let @[<2>%a%a%a@] ≔@ %a@ @]in@ %a@]" | ||
| ident x params_list xs typ a func t func u | ||
| | (P_NLit(i) , _ ) -> out ppf "%s" i | ||
| | (P_NLit(ps, i) , _ ) -> out ppf "%a %s" (raw_path) ps i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "%a.%s" raw_path
and keep arrows aligned ;-)
src/parsing/lpParser.mly
Outdated
|
|
||
| %token <bool * string> DEBUG_FLAGS | ||
| %token <string> INT | ||
| %token <Path.t * string> PINT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing a new token, I suggest to change the type of INT by adding a path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to do that, but since I am not an expert in OcamlLex, I ran into many issues.
This parser is supposed to be replaced by #1129 so I do not think it is a problem.
src/parsing/lpLexer.ml
Outdated
| | "/*" -> comment (qid expl ids) 0 lb | ||
| | regid, '.' -> qid expl (remove_last lb :: ids) lb | ||
| | escid, '.' -> qid expl (remove_useless_escape(remove_last lb) :: ids) lb | ||
| | int -> PINT(ids, Utf8.lexeme lb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ids -> List.rev ids
src/export/rawdk.ml
Outdated
| | P_Type -> out ppf "Type" | ||
| | P_Wild -> out ppf "_" | ||
| | P_NLit i -> string ppf i | ||
| | P_NLit (path, i) -> out ppf "%a%s" Dk.path path i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer literals are undefined in Dedukti. Actually we should fail (already in master) like for string literals. I'm going to change master accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1327.
Oh, I see what you mean now, since it is clearer to me. Yeah, let me find a moment to just change the function |
This is related to #1327: integer literals cannot be translated to dedukti literally. You must add your new test file integers.lp in tests/export_raw_dk.sh. |
- Add Builtin.find_builtin function that searches for a builtin symbol by iterating through all builtin scopes in sig_state.builtins - Add Sig_state.find_builtin with identical implementation and type alias - Replace Builtin.get calls with Builtin.find_builtin throughout codebase to enable cross-module builtin lookup for qualified numeric literals - Update scope.ml to use find_builtin for unqualified paths and get_at for qualified paths in numeric literal desugaring - Modify fol.ml, inductive.ml, rewrite.ml, and tactic.ml to use the new find_builtin function for builtin symbol resolution
…s path first, then search through all other modules
In response to PR review feedback, this commit consolidates the builtin lookup functions into a single function with optional labeled parameters, replacing the previous split between , , and .
a34071c to
f078c81
Compare
|
I've consolidated the val get : sig_state -> ?mp:Path.t -> ?pos:popt -> string -> symI also merged |
I added my test like this and rebased my PR on #1327 but I still have the issue: |
|
Don't do rebasings; do merges instead. Otherwise it's problematic for those following your branch... The history does not matter so much since every thing is squashed into a single commit when I merge a PR. |
|
Hi. There are still some problems: 1) you changed the sig_state type but you shouldn't, 2) your get does not follow the code I proposed which takes care of path aliases, 3) don't use optional arguments in get; this is not useful here. |
What do you mean? You even mention that we should do that in issue #1268
I will fix that
((StrMap.find "nat_succ" ss.builtins).sym_type) |
Right but I changed my mind: I don't think that this is necessary anymore.
Thanks.
But there is no need to change that part of the code. |
|
Or I do not understand a point, or it will not work if we do not change the type of and a second one Z.lp Then, if we have the |
|
Yes. Actually, it will depend on the order of require's. But it will always be possible to write Nat.1. Isn't it what we want? |
let sign =
try Path.Map.find (StrMap.find m ss.alias_path) !loaded
with _ -> assert false (* Should not happen. *)
in
(* Look for the symbol. *)
StrMap.find !(sign.sign_builtins) nameSo this |
|
But Print.builtin needs to be modified to prefix the generated decimal number by the appropriate path. Problem: what is the appropriate path? It should be added in some of the constructors of the notation data type. |
Yes.
Yes. |
|
I added a todo list at the top. |
Previously, Lambdapi only allowed decimal notation (e.g., "0", "+1") to map to a single type, preventing its use across multiple types simultaneously. This change introduces scoped
builtinmappings, enabling users to define decimal notation for multiple types in the same context. This PR, when finished, will close #1268.TODO: